/* GUI CONVERTED from rework.p (converter v1.76) Sun Aug 25 21:00:03 2002 */
/* rework.p - REPETITIVE REWORK TRANSACTION                                   */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.5.4.8 $                                                               */
/* REVISION: 7.3      LAST MODIFIED: 10/31/94   BY: WUG *GN77*                */
/* REVISION: 7.3      LAST MODIFIED: 12/16/94   BY: WUG *G09J*                */
/* REVISION: 7.3      LAST MODIFIED: 03/01/95   BY: WUG *G0G6*                */
/* REVISION: 7.3      LAST MODIFIED: 03/09/95   BY: WUG *G0GR*                */
/* REVISION: 7.3      LAST MODIFIED: 03/26/95   BY: dzn *F0PN*                */
/* REVISION: 7.3      LAST MODIFIED: 11/01/95   BY: ais *G0V9*                */
/* REVISION: 7.3      LAST MODIFIED: 02/21/96   BY: jym *G1M9*                */
/* REVISION: 7.3      LAST MODIFIED: 03/19/96   BY: jym *G1PZ*                */
/* REVISION: 7.3      LAST MODIFIED: 05/16/96   BY: *G1VW* Julie Milligan     */
/* REVISION: 8.6      LAST MODIFIED: 06/11/96   BY: *K001* Alma Lara          */
/* REVISION: 7.3      LAST MODIFIED: 07/02/96   BY: *G1Z7* Julie Milligan     */
/* REVISION: 8.6      LAST MODIFIED: 12/31/96   BY: *H0Q8* Julie Milligan     */
/* REVISION: 8.6      LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 10/25/99   BY: *N002* Bill Gates         */
/* REVISION: 9.1      LAST MODIFIED: 11/17/99   BY: *N04H* Vivek Gogte        */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* Mark Brown         */
/* REVISION: 9.1      LAST MODIFIED: 09/21/00   BY: *N0VN* BalbeerS Rajput    */
/* Revision: 1.5.4.6  BY: Rajesh Thomas         DATE: 06/19/01 ECO: *M18V*    */
/* Revision: 1.5.4.7  BY: Robin McCarthy        DATE: 10/01/01 ECO: *P025*    */
/* $Revision: 1.5.4.8 $       BY: Vivek Gogte           DATE: 08/06/02 ECO: *N1QQ*    */

/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/*V8:ConvertMode=Maintenance                                                  */

{mfdtitle.i "2+ "}
{cxcustom.i "REWORK.P"}

{gldydef.i new}
{gldynrm.i new}

/* MODIFIED CODE TO ELIMINATE USE OF ABBREVIATIONS */
define buffer next_wr_route for wr_route.
define buffer ptmstr for pt_mstr.

define new shared variable rsn_codes as character extent 10.
define new shared variable quantities like wr_qty_comp extent 10.
define new shared variable rework_rsn_codes as character extent 10.
define new shared variable rework_quantities like wr_qty_comp
   extent 10.
define new shared variable wo_recno as recid.
define new shared variable wr_recno as recid.
define new shared variable h_wiplottrace_procs as handle no-undo.
define new shared variable h_wiplottrace_funcs as handle no-undo.
define new shared variable rework_to_lotser like wlt_lotser no-undo.
define new shared variable rework_to_lotser_ref like wlt_ref no-undo.
define new shared variable rework_lotser like wlt_lotser no-undo.
define new shared variable rework_lotser_ref like wlt_ref no-undo.
define new shared variable rework_prodby_op like wl_prodby_op no-undo.

define variable batchqty as decimal.
define variable comp as character.
define variable conv_qty_rwrk as decimal.
define variable cumwo_lot as character.
define variable rejected like mfc_logical.
define variable schedwo_lot as character.
define variable undo_stat like mfc_logical no-undo.
define variable undostat like mfc_logical no-undo.
define variable trans_type as character.
define variable ophist_recid as recid.
define variable yn like mfc_logical.
define variable i as integer.
define variable j as integer.
define variable elapse as decimal format ">>>>>>>>.999".
define variable date_change as integer.
define variable last_op like mfc_logical.
define variable oplist as character.
define variable bomcode as character.
define variable routecode as character.
define variable msg_ct as integer.
define variable lotserials_req as logical.
define variable dont_zero_unissuable as logical initial no.
define variable input_que as logical initial yes.
define variable output_que as logical initial no.
define variable inv-issued as logical no-undo.
define variable move_to_wkctr like wc_wkctr no-undo.
define variable move_to_mch like wc_mch no-undo.

{retrform.i new}
{&REWORK-P-TAG1}

{wlfnc.i} /*FUNCTION FORWARD DECLARATIONS*/
{wlcon.i} /*CONSTANTS DEFINITIONS*/

if is_wiplottrace_enabled() then do:
   {gprunmo.i &program=""wlpl.p"" &module="AWT"
      &persistent="""persistent set h_wiplottrace_procs"""}
   {gprunmo.i &program=""wlfl.p"" &module="AWT"
      &persistent="""persistent set h_wiplottrace_funcs"""}
end.

/* DO NOT RUN PROGRAM UNLESS QAD_WKFL RECORDS HAVE */
/* BEEN CONVERTED SO THAT QAD_KEY2 HAS NEW FORMAT  */
if can-find(first qad_wkfl where qad_key1 = "rpm_mstr") then do:
   /* UTILITY: utrecov2.p MUST BE RUN PRIOR TO EXECUTING THIS PROGRAM */
   {pxmsg.i &MSGNUM=5126 &ERRORLEVEL=3}
   message.
   message.
   leave.
end.

eff_date = today.
find first gl_ctrl no-lock.

{gprun.i ""redflt.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


main:
repeat:
/*GUI*/ if global-beam-me-up then undo, leave.

   /* GET EMP, EFFDATE, SHIFT, SITE, CONTROLTOTAL FROM USER */
   {gprun.i ""retrin1.p"" "(output undo_stat)"}
/*GUI*/ if global-beam-me-up then undo, leave.

   if undo_stat then undo, leave.

   wo-loop:
   repeat:
/*GUI*/ if global-beam-me-up then undo, leave.

      /* GET ITEM, OP, LINE FROM USER */
      {gprun.i ""retrin2.p"" "(output undo_stat)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      if undo_stat then undo, leave.

      /* FIND REPETITIVE SCHEDULE TO UPDATE */
      {gprun.i ""reoptr1b.p""
         "(input site, input line, input part, input op, input eff_date,
           output routing, output bom_code, output schedwo_lot)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      if schedwo_lot = "?" then do:
         /* UNEXPLODED SCHEDULE WITH CONSUMPTION PERIOD */
         {pxmsg.i &MSGNUM=325 &ERRORLEVEL=3}
         next-prompt part.
         undo, retry.
      end.

      /* GET BOM, ROUTING FROM USER */
      {gprun.i ""retrin3.p"" "(output undo_stat)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      if undo_stat then undo, leave.

      /* FIND CUM ORDER.*/
      {gprun.i ""regetwo.p"" "(input site, input part, input eff_date,
               input line, input routing, input bom_code, output cumwo_lot)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      /* VALIDATE THE OPERATION */
      {reopval.i &part = part
         &routing = routing
         &op = op
         &date = eff_date
         &prompt = op
         &frame = "a"
         &leave = ""no""
         &loop = "main"
         }

      /* CREATE IT IF IT DOESN'T EXIST */
      if cumwo_lot = ? then do:
         {gprun.i ""recrtwo.p"" "(input site, input part,
                  input eff_date, input line, input routing, input bom_code,
                  output cumwo_lot)"}
/*GUI*/ if global-beam-me-up then undo, leave.


         if cumwo_lot = ? then next wo-loop.
         display cumwo_lot @ wo_lot with frame a.
      end.
      else do:
         display cumwo_lot @ wo_lot with frame a.
         find wo_mstr where wo_lot = cumwo_lot no-lock.

         if wo_status = "c" then do:
            /* CUM ORDER IS CLOSED */
            {pxmsg.i &MSGNUM=5101 &ERRORLEVEL=3}
            undo, retry.
         end.
      end.

      find wr_route where wr_lot = cumwo_lot and wr_op = op
         no-lock no-error.
      if not available wr_route then do:
         /* OPERATION DOES NOT EXIST */
         {pxmsg.i &MSGNUM=106 &ERRORLEVEL=3}
         next-prompt op with frame a.
         undo, retry.
      end.

      if not wr_milestone then do:
         /* OPERATION NOT A MILESTONE */
         {pxmsg.i &MSGNUM=560 &ERRORLEVEL=2}

         if is_wiplottrace_enabled() then do:
            if prev_milestone_operation(cumwo_lot, op) <> ?
               and is_operation_queue_lot_controlled
               (cumwo_lot,
               prev_milestone_operation(cumwo_lot, op),
               OUTPUT_QUEUE)
            then do:
               {pxmsg.i &MSGNUM=8465 &ERRORLEVEL=3}
               /* WIP LOT TRACE IS ENABLED AND OPERATION IS A NON-MILESTONE */
               undo, retry.
            end.
         end.
      end.

      find first wr_route where wr_lot = cumwo_lot and wr_op > op
         no-lock no-error.
      last_op = not available wr_route.

      find wr_route where wr_lot = cumwo_lot and wr_op = op no-lock.

      display wr_desc with frame a.

      assign
         wkctr = ""
         mch = ""
         dept = ""
         um = ""
         conv = 1
         qty_rwrk = 0
         rwrk_rsn_code = ""
         rwrk_multi_entry = no
         mod_issrc = no
         start_run = ""
         act_run_hrs = 0
         stop_run = ""
         earn_code = ""
         to_op = op
         rsn_codes = ""
         quantities = 0
         rework_rsn_codes = ""
         rework_quantities = 0
         to_que = output_que
         wkctr = wr_wkctr
         mch = wr_mch
         .

      find wc_mstr where wc_wkctr = wkctr and wc_mch = mch no-lock.

      dept = wc_dept.
      find dpt_mstr where dpt_dept = wc_dept no-lock no-error.

      find wo_mstr where wo_lot = cumwo_lot no-lock.
      find pt_mstr where pt_part = wo_part no-lock.
      um = pt_um.

      find first ea_mstr no-lock where ea_type = "1" no-error.
      if available ea_mstr then earn_code = ea_earn.

      display
         wkctr
         mch
         wc_desc
         dept
         dpt_desc          when (available dpt_mstr)
         ""                when (not available dpt_mstr) @ dpt_desc
         um
         conv
         qty_rwrk
         rwrk_rsn_code
         rwrk_multi_entry
         mod_issrc
         start_run
         act_run_hrs
         stop_run
         earn_code
         ea_desc           when (available ea_mstr)
         ""                when (not available ea_mstr) @ ea_desc
         to_op
         "" @ wr_desc
         to_que
      with frame rework1.
      .

      if is_wiplottrace_enabled()
      then
         run init_rework_input_wip_lot
            in h_wiplottrace_procs.

      do with frame rework1 on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.


         for each sr_wkfl exclusive-lock
               where sr_userid = mfguser:
            delete sr_wkfl.
         end.

         for each pk_det exclusive-lock
               where pk_user = mfguser:
            delete pk_det.
         end.

         {gprun.i ""reworki1.p"" "(input cumwo_lot, input op,
                  output undo_stat)"}
/*GUI*/ if global-beam-me-up then undo, leave.


         if undo_stat then undo main, retry main.

         conv_qty_rwrk = qty_rwrk * conv.

         /* CHECK QUEUES IF WOULD GO NEGATIVE; IF SO ISSUE MESSAGES */

         msg_ct = 0.

         /* CHECK REJECT QUEUE */
         {gprun.i ""rechkq.p""
            "(input cumwo_lot, input op,
              input ""r"",
              input (- conv_qty_rwrk),
              input-output msg_ct)"}
/*GUI*/ if global-beam-me-up then undo, leave.


         if to_que = input_que then do:

            /* CHECK INPUT QUEUE */
            {gprun.i ""rechkq.p"" "(input cumwo_lot, input to_op,
                     input ""i"",
                     input conv_qty_rwrk,
                     input-output msg_ct)"}
/*GUI*/ if global-beam-me-up then undo, leave.


         end.
         else do:
            /* CHECK OUTPUT QUEUE */
            {gprun.i ""rechkq.p"" "(input cumwo_lot, input to_op,
                     input ""o"",
                     input conv_qty_rwrk,
                     input-output msg_ct)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         end.

         /* FORCE A PAUSE IF NECESSARY */
         {gprun.i ""repause.p"" "(input msg_ct)"}
/*GUI*/ if global-beam-me-up then undo, leave.


         /* MODIFY COMPONENT PART ISSUE LIST */
         if mod_issrc then do:

            {gprun.i ""recrtcl.p""
               "(input cumwo_lot, input op, input yes, input 0,
                 input eff_date, input dont_zero_unissuable,
                 input wkctr,
                 output rejected, output lotserials_req)"}
/*GUI*/ if global-beam-me-up then undo, leave.


            hide frame rework1 no-pause.
            hide frame a no-pause.

            display
               site
               part
               op
               line
            with frame b side-labels width 80 attr-space.

            {gprun.i ""reisslst.p""
               "(input cumwo_lot, input part, input site,
                 input eff_date, input wkctr,
                 input 0, output undo_stat)"}
/*GUI*/ if global-beam-me-up then undo, leave.


            hide frame b no-pause.
            view frame a.
            view frame rework1.
            if undo_stat then undo, retry.
         end.

         find wo_mstr where wo_lot = cumwo_lot no-lock.
         wo_recno = recid(wo_mstr).
         find wr_route where wr_lot = cumwo_lot and wr_op = op no-lock.
         wr_recno = recid(wr_route).

         /* ADDED FOURTH PARAMETER eff_date IN CALL TO mpwindow.i */

         {mpwindow.i
            wo_part
            op
            "if wo_routing = """" then wr_part else wo_routing"
            eff_date
            }

         if is_wiplottrace_enabled()
            and is_operation_queue_lot_controlled(cumwo_lot, op,
            REJECT_QUEUE)
         then do:

            run get_destination_wkctr_mch_from_user
               in h_wiplottrace_procs
               (input cumwo_lot,
               input to_op,
               output move_to_wkctr,
               output move_to_mch,
               output undo_stat).

            if undo_stat then undo, retry.

            run get_rework_input_wip_lot_from_user

               (input cumwo_lot,
               input op,
               input qty_rwrk,
               input to_op,
               if to_que = input_que then INPUT_QUEUE else OUTPUT_QUEUE,
               input conv,
               input um,
               input site, input wkctr, input mch,
               input move_to_wkctr, move_to_mch,
               output undo_stat).

            if undo_stat then
               undo, retry.
         end.

         yn = yes.
         /* PLEASE CONFIRM UPDATE */
         {pxmsg.i &MSGNUM=32 &ERRORLEVEL=1 &CONFIRM=yn &CONFIRM-TYPE='LOGICAL'}
         if yn <> yes then undo, retry.

         {&REWORK-P-TAG2}
         /* NOW THAT WE HAVE LAST INPUT FROM USER, RECHECK INVENTORY*/

         {gprun.i ""reoptr1f.p""
            "(input """",
              output inv-issued)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         if inv-issued then undo, retry.
      end.
/*GUI*/ if global-beam-me-up then undo, leave.


      /****************************************************************/
      /*GOT ALL DATA AND VALIDATED IT, NOW WE CAN DO SOMETHING WITH IT*/
      /****************************************************************/

      /* NO TRANSACTION SHOULD BE PENDING HERE */
      {gprun.i ""gpistran.p"" "(input 1, input """")"}
/*GUI*/ if global-beam-me-up then undo, leave.


      ophist_recid = ?.

      if is_wiplottrace_enabled()
         and is_operation_queue_lot_controlled (cumwo_lot, op,
         REJECT_QUEUE)
      then
         run rework_rework_wip_lots
            (cumwo_lot, op, emp, site, wkctr, mch, dept, shift, eff_date,
            if to_que = input_que then INPUT_QUEUE else OUTPUT_QUEUE,
            to_op, conv_qty_rwrk, rwrk_rsn_code, act_run_hrs, earn_code,
            move_to_wkctr, move_to_mch).
      else do:

         /* PROCESS REWORK QUANTITIES */
         if rwrk_multi_entry then do:
            do i = 1 to 10:
               if rework_quantities[i] <> 0 then do:
                  trans_type = "REWORK".
                  conv_qty_rwrk = rework_quantities[i] * conv.

                  {gprun.i ""reophist.p"" "(input trans_type,
                        input cumwo_lot, input op, input emp,
                        input wkctr, input mch, input dept, input shift,
                        input eff_date,
                        output ophist_recid)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                  {gprun.i ""reworka.p""
                     "(input cumwo_lot, input op,
                        input to_op,
                        input rework_rsn_codes[i],
                        input ophist_recid,
                        input conv_qty_rwrk)"}
/*GUI*/ if global-beam-me-up then undo, leave.

               end.
            end.
         end.
         else do:
            trans_type = "REWORK".

            {gprun.i ""reophist.p"" "(input trans_type,
                  input cumwo_lot, input op, input emp,
                  input wkctr, input mch, input dept, input shift,
                  input eff_date,
                  output ophist_recid)"}
/*GUI*/ if global-beam-me-up then undo, leave.


            conv_qty_rwrk = qty_rwrk * conv.

            {gprun.i ""reworka.p""
               "(input cumwo_lot, input op,
                  input to_op,
                  input rwrk_rsn_code,
                  input ophist_recid,
                  input conv_qty_rwrk)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         end.

         /* MOVE TO OUTQUE OF TARGET OPERATION IF DIFFERENT THAN THIS OP */
         conv_qty_rwrk = qty_rwrk * conv.
         global_addr = string(ophist_recid).

         if not last_op then do:
            if to_que = input_que then do:

               /* MOVE IT TO THE OUTQUE OF THE OP PREVIOUS TO THE TO OPERATION */
               find last wr_route
                  where wr_lot = cumwo_lot and wr_op < to_op no-lock.

               {gprun.i ""reworkb.p""
                   "(input cumwo_lot,
                     input op,
                     input wr_op,
                     input emp,
                     input shift,
                     input eff_date,
                     input conv_qty_rwrk)"}
/*GUI*/ if global-beam-me-up then undo, leave.


               trans_type = "REWORK".

               /* NOW MOVE IT FROM THE OUTQUE TO INQUE OF THE "TO" OP */
               {gprun.i ""reophist.p"" "(input trans_type,
                     input cumwo_lot, input wr_op, input emp,
                     input wkctr, input mch, input dept, input shift,
                     input eff_date,
                     output ophist_recid)"}
/*GUI*/ if global-beam-me-up then undo, leave.


               {gprun.i ""removea.p""
                  "(input cumwo_lot, input wr_op, input eff_date,
                    input ophist_recid, input conv_qty_rwrk)"}
/*GUI*/ if global-beam-me-up then undo, leave.


            end.
            else do:
               /* MOVE IT TO THE OUTQUE OF THE TO OPERATION */
               {gprun.i ""reworkb.p""
                   "(input cumwo_lot,
                     input op,
                     input to_op,
                     input emp,
                     input shift,
                     input eff_date,
                     input conv_qty_rwrk)"}
/*GUI*/ if global-beam-me-up then undo, leave.

            end.
         end.

         /* LABOR AND BURDEN TRANSACTIONS */
         if ophist_recid = ? then do:
            trans_type = "REWORK".

            {gprun.i ""reophist.p"" "(input trans_type,
                  input cumwo_lot, input op, input emp,
                  input wkctr, input mch, input dept, input shift,
                  input eff_date,
                  output ophist_recid)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         end.

         {gprun.i ""relbra.p"" "(input cumwo_lot, input op,
               input wkctr, input mch, input dept, input act_run_hrs,
               input eff_date, input earn_code, input emp, input true,
               input ophist_recid)"}
/*GUI*/ if global-beam-me-up then undo, leave.


         /* ISSUE COMPONENTS */

         {gprun.i ""rebkflis.p"" "(input cumwo_lot, input eff_date,
               input ophist_recid)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      end.

      global_addr = string(ophist_recid).
      {gprun.i ""reintchk.p"" "(input cumwo_lot)"}
/*GUI*/ if global-beam-me-up then undo, leave.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.

end.
/*GUI*/ if global-beam-me-up then undo, leave.


if is_wiplottrace_enabled() then
   delete PROCEDURE h_wiplottrace_procs no-error.
if is_wiplottrace_enabled() then
   delete PROCEDURE h_wiplottrace_funcs no-error.

PROCEDURE rework_rework_wip_lots:
   define input parameter ip_wo_id like wl_prodby_id no-undo.
   define input parameter ip_wo_op like wl_prodby_op  no-undo.
   define input parameter ip_emp like op_emp no-undo.
   define input parameter ip_site like si_site no-undo.
   define input parameter ip_wkctr like wc_wkctr no-undo.
   define input parameter ip_mch like wc_mch no-undo.
   define input parameter ip_dept like wc_dept no-undo.
   define input parameter ip_shift like op_shift no-undo.
   define input parameter ip_effdate like op_date no-undo.
   define input parameter ip_queue as character no-undo.
   define input parameter ip_to_op as integer no-undo.
   define input parameter ip_qty as decimal no-undo.
   define input parameter ip_reason_code like rsn_code no-undo.
   define input parameter ip_act_run_hrs as decimal no-undo.
   define input parameter ip_earn_code as character no-undo.
   define input parameter ip_move_to_wkctr like wc_wkctr no-undo.
   define input parameter ip_move_to_mch like wc_mch no-undo.

   define variable trans_type as character no-undo.
   define variable ophist_recid as recid no-undo.
   define variable first_ophist_recid as recid no-undo.
   define variable lot_number_changed like mfc_logical no-undo.

   for first wo_mstr where wo_lot = ip_wo_id no-lock:
   end.

   lot_number_changed = rework_to_lotser <> rework_lotser.

   trans_type = "REWORK".

   {gprun.i ""reophist.p""
      "(input trans_type,
        input ip_wo_id,
        input ip_wo_op,
        input ip_emp,
        input ip_wkctr,
        input ip_mch,
        input ip_dept,
        input ip_shift,
        input ip_effdate,
        output first_ophist_recid)"}
/*GUI*/ if global-beam-me-up then undo, leave.


   ophist_recid = first_ophist_recid.

   do transaction:
      for first op_hist where
         recid(op_hist) = ophist_recid exclusive-lock:
      end.

      assign
         op_wip_lotser = rework_lotser
         op_wip_ref = rework_lotser_ref.

      {gprun.i ""reworka.p""
         "(input ip_wo_id,
           input ip_wo_op,
           input ip_to_op,
           input ip_reason_code,
           input ophist_recid,
           input ip_qty)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      if ip_to_op <> ip_wo_op then do:
         if ip_queue = INPUT_QUEUE then do:
            /* MOVE IT TO THE OUTQUE OF THE OP */
            /* PREVIOUS TO THE TO OPERATION    */

            {gprun.i ""reworkb.p""
               "(input ip_wo_id,
                 input ip_wo_op,
                 input prev_operation(ip_wo_id, ip_to_op),
                 input ip_emp,
                 input ip_shift,
                 input ip_effdate,
                 input ip_qty)"}
/*GUI*/ if global-beam-me-up then undo, leave.


            /* NOW MOVE IT FROM THE OUTQUE */
            /* TO INQUE OF THE "TO" OP     */

            trans_type = "REWORK".

            {gprun.i ""reophist.p""
               "(input trans_type,
                 input ip_wo_id,
                 input prev_operation(ip_wo_id, ip_to_op),
                 input ip_emp,
                 input ip_move_to_wkctr,
                 input ip_move_to_mch,
                 input ip_dept,
                 input ip_shift,
                 input ip_effdate,
                 output ophist_recid)"}
/*GUI*/ if global-beam-me-up then undo, leave.


            {gprun.i ""removea.p""
               "(input ip_wo_id,
                 input prev_operation(ip_wo_id, ip_to_op),
                 input ip_effdate,
                 input ophist_recid,
                 input ip_qty)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         end. /* if ip_queue = INPUT_QUEUE */
         else do:
            /* MOVE IT TO THE OUTQUE OF THE TO OPERATION */

            {gprun.i ""reworkb.p""
               "(input ip_wo_id,
                 input ip_wo_op,
                 input ip_to_op,
                 input ip_emp,
                 input ip_shift,
                 input ip_effdate,
                 input ip_qty)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         end. /* else do*/
      end. /* if ip_to_op <> ip_wo_op */

      /* REDUCE THE REJECT QUEUE WIP QOH AT THIS OPERATION */
      /* FOR THE "FROM" LOT                                */

      run change_wip_qty_alloc_qoh in h_wiplottrace_procs
         (input ip_wo_id,
         input rework_prodby_op,
         input rework_lotser,
         input rework_lotser_ref,
         input ip_site,
         input ip_wkctr,
         input ip_mch,
         input REJECT_QUEUE,
         input ip_wo_id,
         input ip_wo_op,
         input - ip_qty).

      /* INCREASE THE OUTPUT QUEUE WIP QOH AT THE "TO" OPERATION */
      /* FOR THE "TO" LOT                                        */

      run change_wip_qty_alloc_qoh in h_wiplottrace_procs
         (input ip_wo_id,
         input rework_prodby_op,
         input rework_to_lotser,
         input rework_to_lotser_ref,
         input ip_site,
         input ip_move_to_wkctr,
         input ip_move_to_mch,
         input ip_queue,
         input ip_wo_id,
         input ip_to_op,
         input ip_qty).

      /* UPDATE THE WIP LOT MASTER - QTY REWORKED */

      run update_wip_lot_master_record in h_wiplottrace_procs
         (input ip_wo_id,
         input rework_prodby_op,
         input rework_lotser,
         input CUM_REWORKED,
         input ip_qty).

      if lot_number_changed then do:
         /* REGISTER THE OLD LOT AS CONSUMED IN THE TRACING JOURNAL. */
         /* NOTE THAT WE SAY IT'S PRODUCED BY THE PRIOR OPERATION    */
         /* UNLESS WE'RE AT THE FIRST OPERATION.                     */

         run add_trace_record in h_wiplottrace_procs
            (input OPERATION_HISTORY,
            input op_trnbr,
            input CONSUMED_MTL,
            input WIP_MTL,
            input ip_wo_id,
            input rework_prodby_op,
            input wo_part,
            input rework_lotser,
            input '',
            input ip_qty).

         /* UPDATE THE WIP LOT MASTER - QTY CONSUMED */

         run update_wip_lot_master_record in h_wiplottrace_procs
            (input ip_wo_id,
            input rework_prodby_op,
            input rework_lotser,
            input CUM_CONSUMED,
            input ip_qty).

         /* REGISTER THE NEW LOT AS PRODUCED IN THE TRACING JOURNAL */

         run add_trace_record in h_wiplottrace_procs
            (input OPERATION_HISTORY,
            input op_trnbr,
            input PRODUCED_MTL,
            input WIP_MTL,
            input ip_wo_id,
            input rework_prodby_op,
            input wo_part,
            input rework_to_lotser,
            input '',
            input ip_qty).

         /* UPDATE THE WIP LOT MASTER - QTY PRODUCED */

         run update_wip_lot_master_record in h_wiplottrace_procs
            (input ip_wo_id,
            input rework_prodby_op,
            input rework_to_lotser,
            input CUM_PRODUCED,
            input ip_qty).
      end. /*if lot_number_changes*/
   end. /* do transaction*/

   /* LABOR AND BURDEN TRANSACTIONS */

   {gprun.i ""relbra.p"" "(input ip_wo_id, input ip_wo_op,
                input ip_wkctr, input ip_mch, input ip_dept,
                input ip_act_run_hrs, input ip_effdate, input ip_earn_code,
                input ip_emp, input true, input first_ophist_recid)"}
/*GUI*/ if global-beam-me-up then undo, leave.


   /* ISSUE COMPONENTS */

   {gprun.i ""rebkflis.p"" "(input ip_wo_id, input ip_effdate,
                input first_ophist_recid)"}
/*GUI*/ if global-beam-me-up then undo, leave.


   global_addr = string(ophist_recid).
END PROCEDURE.

PROCEDURE get_rework_input_wip_lot_from_user:
   define input parameter ip_wo_id like wl_prodby_id no-undo.
   define input parameter ip_wo_op like wl_prodby_op  no-undo.
   define input parameter ip_qty like wlt_qty no-undo.
   define input parameter ip_to_op like wl_prodby_op no-undo.
   define input parameter ip_to_queue as character no-undo.
   define input parameter ip_umconv_factor as decimal no-undo.
   define input parameter ip_um as character no-undo.
   define input parameter ip_site like si_site no-undo.
   define input parameter ip_wkctr like wc_wkctr no-undo.
   define input parameter ip_mch like wc_mch no-undo.
   define input parameter ip_move_to_wkctr like wc_wkctr no-undo.
   define input parameter ip_move_to_mch like wc_mch no-undo.
   define output parameter op_undo_all like mfc_logical no-undo.

   {gprunmo.i
      &program = ""wluirwi.p""
      &module = "AWT"
      &param = """(input ip_wo_id,
                   input ip_wo_op,
                   input ip_qty,
                   input ip_to_op,
                   input ip_to_queue,
                   input ip_umconv_factor,
                   input ip_um,
                   input ip_site,
                   input ip_wkctr,
                   input ip_mch,
                   input ip_move_to_wkctr,
                   input ip_move_to_mch,
                   output op_undo_all)"""}

END PROCEDURE.
